/*package com.xiao.mp3.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class C3p0ConnectionPoolUtil {

	private static ComboPooledDataSource c3p0DataSource = new ComboPooledDataSource();

	static{
		init();
	}
	
	private static void init(){
		String driver = "";
		String url = "";
		String username = "";
		String password = "";

		Properties p = LoadProperties.getProperties();
		try {
			if (p.containsKey("db.driver")) {
				driver = p.getProperty("db.driver");
			}
			if (p.containsKey("db.url")) {
				url = p.getProperty("db.url");
			}
			if (p.containsKey("db.username")) {
				username = p.getProperty("db.username");
			}
			if (p.containsKey("db.password")) {
				password = p.getProperty("db.password");
			}
		} catch (Exception ex) {
			Logger.getLogger(C3p0ConnectionPoolUtil.class.getName())
					.log(Level.SEVERE, null, ex);
		}
//			Class.forName(driver);
//			conn = DriverManager.getConnection(url, username, password);
		try {
			c3p0DataSource.setUser(username);
			c3p0DataSource.setPassword(password);
			c3p0DataSource.setJdbcUrl(url);
			c3p0DataSource.setDriverClass(driver);
			c3p0DataSource.setAcquireIncrement(10);//连接数耗尽，每次新申请的连接数
			c3p0DataSource.setAcquireRetryDelay(1000);//两次连接的间隔时间，毫秒
			c3p0DataSource.setAcquireRetryAttempts(20);//失败重试次数
			c3p0DataSource.setAutoCommitOnClose(false);
			c3p0DataSource.setAutomaticTestTable("TEST_C3P0");//如果设置则下面的一个设置被忽略
			c3p0DataSource.setPreferredTestQuery("select 1");
			c3p0DataSource.setMaxIdleTime(150);//最大空闲时间,150秒内未使用则连接被丢弃
			c3p0DataSource.setMaxPoolSize(100);
			c3p0DataSource.setMinPoolSize(10);
			//每60秒检查所有连接池中的空闲连接，用来解决mysql将超过8个小时的连接给取消，而连接池还认为该连接有效
			c3p0DataSource.setIdleConnectionTestPeriod(60);
			c3p0DataSource.setInitialPoolSize(15);//初始化连接数
			c3p0DataSource.setUnreturnedConnectionTimeout(500);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
		
	public static Connection getConn() {
		Connection conn = null;
		try{
			conn = c3p0DataSource.getConnection();
		} catch (Exception ex) {
			ex.printStackTrace();
			System.out.print("连接异常");
		}
		return conn;
	}

	public static void connClose(Connection conn) {
		try {
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void preClose(PreparedStatement pre) {
		try {
			pre.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void resClose(ResultSet res) {
		try {
			res.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
*/